package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.Orders;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Mapper
public interface OrderMapper {

    /**
     * 插入订单数据
     * @param order
     */
    void insert(Orders order);

    /**
     * 分页查询
     * @param orders
     * @return
     */
    Page<Orders> page(OrdersPageQueryDTO dto);

    /**
     * 根据订单id查询
     * @param id
     * @return
     */
    @Select("select id, number, status, user_id, address_book_id, order_time, checkout_time, pay_method, pay_status, amount, " +
            "            remark, phone, address, user_name, consignee, cancel_reason, rejection_reason, cancel_time, estimated_delivery_time, " +
            "            delivery_status, delivery_time, pack_amount, tableware_number, tableware_status\n" +
            "        from orders where id = #{id}")
    Orders getById(Long id);

    /**
     * 修改订单
     * @param update
     */
    void update(Orders update);

    /**
     * 查询所有订单
     * @return
     */
    @Select("select id, number, status, user_id, address_book_id, order_time, checkout_time, pay_method, pay_status, amount, " +
            "            remark, phone, address, user_name, consignee, cancel_reason, rejection_reason, cancel_time, estimated_delivery_time, " +
            "            delivery_status, delivery_time, pack_amount, tableware_number, tableware_status " +
            "        from orders")
    List<Orders> list();

    /**
     * 根据订单状态查询
     * @param status
     * @return
     */
    @Select("select id, number, status, user_id, address_book_id, order_time, checkout_time, pay_method, pay_status, amount, " +
            "            remark, phone, address, user_name, consignee, cancel_reason, rejection_reason, cancel_time, estimated_delivery_time, " +
            "            delivery_status, delivery_time, pack_amount, tableware_number, tableware_status " +
            "        from orders where status = #{status}")
    List<Orders> listByStatus(Integer status);

    /**
     * 根据动态条件统计营业额
     * @param map
     */
    Double sumByMap(Map map);

    /**
     * 查询指定条件集合
     * @param map
     * @return
     */
    List<Orders> listByMap(Map<String, Object> map);

    /**
     * 根据动态条件统计订单数量
     * @param map
     * @return
     */
    Integer countByMap(Map map);
}
